package com.bluesky.plum.uimodels.standard;

import com.bluesky.plum.richdomain.FieldType;
import com.bluesky.plum.richdomain.RichDomainField;
import com.bluesky.plum.uimodels.standard.components.EventListener;

public class FieldUIComponent extends UIComponent {

	protected RichDomainField field;

	protected FieldType fieldType;

	protected EventListener valueChangeEventListener;

	public FieldUIComponent(RichDomainField field) {
		this.field = field;

		// copy some fields
		this.name = field.name;
		this.caption = field.caption;
		this.fieldType = field.fieldType;

	}

	public boolean hasField() {
		return getField() != null;
	}

	/**
	 * it is for when updating the POJO model from UI component.
	 */
	public Object getDomainFieldValue() {
		// it is abstract really.
		return null;
	}

	public void setDomainFieldValue(Object value) {

	}

	@Override
	public String toString() {

		return String.format("%-20s%-20s%s", this.getClass().getSimpleName(),
				name, field);
	}

	public RichDomainField getField() {
		return field;
	}

	public void setField(RichDomainField field) {
		this.field = field;
	}

	public FieldType getFieldType() {
		return fieldType;
	}

	public void setFieldType(FieldType fieldType) {
		this.fieldType = fieldType;
	}

	public EventListener getValueChangeEventListener() {
		return valueChangeEventListener;
	}

	public void setValueChangeEventListener(
			EventListener valueChangeEventListener) {
		this.valueChangeEventListener = valueChangeEventListener;
	}
}
